﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using FreeProperty.Data;


namespace FreeProperty.Views.Shared
{
    public class SiteBasePage : System.Web.UI.Page
    {
        public SiteBasePage()
        {
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            //if (HttpContext.Current.Session[FreePropertyConstants.SESSION_SEARCH_QUERY] == null)
            //{
            //    Server.Transfer("~/ErrorMessage.aspx");
            //}
            if (ActiveUser.ID.IsNull)
            {
                Response.Write("<script>ShowLogout(false);</script>");
            }
            else
            {
                Response.Write("<script>ShowLogout(true);</script>");
            }
        }
        public UserInfo ActiveUser
        {
            get
            {
                if (Session[FreePropertyConstants.SESSION_ACTIVE_USER] == null)
                {
                    //Response.Redirect("~/User/UserLogin.aspx");
                    return new UserInfo();
                }
                else
                {
                    return (UserInfo)Session[FreePropertyConstants.SESSION_ACTIVE_USER];
                }
            }
        }
        protected override void OnError(EventArgs e)
        {
            base.OnError(e);
            Session[FreePropertyConstants.SESSION_EXCEPTION] = this.Server.GetLastError();
            this.Server.ClearError();
            Response.Redirect("~/ErrorMessage.aspx");
        }
        protected string GetBaseURL()
        {

            string sBaseURL = "";
            string sVirtualPath = "";
            if (HttpRuntime.AppDomainAppVirtualPath != "/")
            {
                sVirtualPath = HttpRuntime.AppDomainAppVirtualPath + "/";
            }
            else
            {
                sVirtualPath = HttpRuntime.AppDomainAppVirtualPath;
            }
            sBaseURL = "http://" + Request.Url.Authority + sVirtualPath;
            return sBaseURL;
        }
    }
    public class SiteBasePageWithSession : SiteBasePage
    {
        public SiteBasePageWithSession()
        {
        }
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            if (ActiveUser.ID.IsNull)
            {
                Session[FreePropertyConstants.SESSION_LOGIN_URL] = Request.AppRelativeCurrentExecutionFilePath;
                Response.Redirect("../User/UserLogin.aspx");
            }

        }
        
    }
}